<?php
require_once "./db_config.php";
$name=$_POST['user'];
$password=MD5($_POST['password']);
class DATA{
  public $message='';
  public $type='';
  public $name='';
  public $dept='';
  public $id='';
}
$data=new DATA;
if($name && $password){
  $sql="SELECT * FROM login WHERE id='$name'";
  $result=mysqli_query($conn,$sql);
  if (mysqli_num_rows($result) > 0) {
    // 输出数据
    $row = mysqli_fetch_array($result);
    if($row['password']==$password){
      $data->message='登录成功！';
      $data->type='success';
      $data->id=$row['id'];
      $data->name=$row['name'];
      $data->dept=$row['dept'];
      $data->role=$row['role'];
      echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }else {
      $data->message='密码不正确，请重新输入！';
      $data->type='error';
      echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }
  }else{
    $data->message='该用户不存在，请重新输入！';
    $data->type='error';
    echo json_encode($data,JSON_UNESCAPED_UNICODE);
  }
}
